#!/usr/bin/with-contenv bashio
# vim: ft=bash
# shellcheck shell=bash
# ==============================================================================
# Start Z-Wave JS service for Z-Wave radio
# ==============================================================================
SERIAL_DEVICE=$(bashio::config 'device')

# Emulate serial Hardware for test & development
if bashio::config.true 'emulate_hardware'; then
    SERIAL_DEVICE="--mock-driver"
fi

# Send out discovery information to Home Assistant
./discovery &

# Set external config directory
export ZWAVEJS_EXTERNAL_CONFIG=/data/db

# Run daemon, passing external config directory in as environment variable
# shellcheck disable=SC2086
exec zwave-server ${SERIAL_DEVICE} --config /etc/zwave_config.json --disable-dns-sd
